package com.ninong.ker.admin.service.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ninong.ker.admin.domain.FwGroupData;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ActTaskDTO {

    private static final long serialVersionUID = 1L;

    private String id;

    private String ower;

    private String name;

    private String status;

    /**
     * DONE 已办任务
     * NEED 待办任务
     */
    private String taskType;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createdDate;
    private String instanceName;
    private String definitionKey;
    private String businessKey;
    /**
     * 搜索值
     */
    private String searchValue;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 更新者
     */
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /**
     * 备注
     */
    private String remark;

    private String gid;
    private String did;

    /**
     * 申请人
     */
    private String createName;

    private Integer currentPage;

    private Integer pageSize;

    public ActTaskDTO(Task task, ProcessInstance processInstance, FwGroupData data) {
        this.id = task.getId();
        this.name = task.getName();
        this.instanceName = processInstance.getProcessDefinitionName();
        this.definitionKey = processInstance.getProcessDefinitionKey();
        this.businessKey = processInstance.getBusinessKey();
        if(ObjectUtils.isNotEmpty(data)){
            this.createName = data.getCreateName();
            this.createTime = data.getCreateTime();
            this.gid = data.getGid();
            this.did = data.getId();
        }
    }

    public ActTaskDTO(HistoricProcessInstance task, FwGroupData data) {
        this.id = task.getId();
        this.instanceName = task.getProcessDefinitionName();
        if(ObjectUtils.isNotEmpty(data)){
            this.createName = data.getCreateName();
            this.createTime = data.getCreateTime();
            this.gid = data.getGid();
            this.did = data.getId();
        }
    }
}
